package com.example.himalaya.model.api;

import com.ximalaya.ting.android.opensdk.constants.DTransferConstants;
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest;
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack;
import com.ximalaya.ting.android.opensdk.model.album.AlbumList;
import com.ximalaya.ting.android.opensdk.model.album.AnnouncerListByIds;
import com.ximalaya.ting.android.opensdk.model.announcer.AnnouncerCategoryList;
import com.ximalaya.ting.android.opensdk.model.announcer.AnnouncerList;
import com.ximalaya.ting.android.opensdk.model.track.AnnouncerTrackList;

import java.util.HashMap;
import java.util.Map;

public class AnnouncerDataApi {

    private AnnouncerDataApi() {

    }

    private static AnnouncerDataApi sAnnouncerDataApi;

    public static AnnouncerDataApi getInstance() {
        if (sAnnouncerDataApi == null) {
            synchronized (AnnouncerDataApi.class) {
                if (sAnnouncerDataApi == null) {
                    sAnnouncerDataApi = new AnnouncerDataApi();
                }
            }
        }

        return sAnnouncerDataApi;
    }

    /**
     * 3.8.1 获取喜马拉雅主播分类
     */
    public  void getAnnouncerCategoryList(IDataCallBack<AnnouncerCategoryList> callback) {
        Map<String, String> specificParams = new HashMap<>();
        CommonRequest.getAnnouncerCategoryList(specificParams, callback);
    }

    /**
     * 3.8.2 获取某个分类下的主播列表
     *
     * @param vcategory_id 主播分类ID 必填
     * @param page         当前页
     * @param count        请求数量
     * @param callback     回调函数
     */
    public  void getAnnouncerList(String vcategory_id, int page, int count, String calc_dimension, final IDataCallBack<AnnouncerList> callback) {

        Map<String, String> map = new HashMap<>();
        map.put(DTransferConstants.VCATEGORY_ID, vcategory_id);
        map.put(DTransferConstants.CALC_DIMENSION, calc_dimension);    // 返回的主播列表排序规则，取值和含义如下：1-最火 ，2-最新，3-粉丝最多
        map.put(DTransferConstants.PAGE, page + "");
        map.put(DTransferConstants.PAGE_SIZE, count + "");
        CommonRequest.getAnnouncerList(map, callback);
    }

    /**
     * 3.8.3 获取主播的专辑列表
     *
     * @param aid      主播用户ID 必填
     * @param page     当前页
     * @param count    请求数量
     * @param callback 回调函数
     */
    public  void getAlbumsByAnnouncer(int aid, int page, int count, final IDataCallBack<AlbumList> callback) {
        Map<String, String> map = new HashMap<>();
        map.put(DTransferConstants.AID, aid + "");
        map.put(DTransferConstants.PAGE, page + "");
        map.put(DTransferConstants.PAGE_SIZE, count + "");
        CommonRequest.getAlbumsByAnnouncer(map, callback);
    }

    /**
     * 3.8.4 获取某个主播的声音列表
     *  @param aid      主播用户ID 必填
     * @param page     当前页
     * @param count    请求数量
     * @param callback 回调函数
     */
    public  void getTracksByAnnouncer(long aid, int page, int count, final IDataCallBack<AnnouncerTrackList> callback) {
        Map<String, String> map = new HashMap<>();

        map.put(DTransferConstants.AID, aid + "");
        map.put(DTransferConstants.PAGE, page + "");
        map.put(DTransferConstants.PAGE_SIZE, count + "");

        CommonRequest.getTracksByAnnouncer(map, callback);
    }

    /**
     * 3.8.5 根据主播ID批量获取主播信息
     *
     * @param aid      主播用户ID 必填
     * @param callback 回调函数
     */
    public  void getAnnouncersBatch(int aid, final IDataCallBack<AnnouncerListByIds> callback) {
        Map<String, String> maps = new HashMap<>();
        maps.put("ids", aid + "");

        CommonRequest.getAnnouncersBatch(maps, callback);
    }
}